home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue31 / delcom / PageDefn.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-02-06  |  9.4 KB  |  249 lines

  1. unit PageDefn;
  2. {********************************************************************}
  3. {**  Unit : Pagedefn                                               **}
  4. {**                                                                **}
  5. {**  Description : This unit contains the dialog proc and callback **}
  6. {**  for the created PropertyPage. This is done                    **}
  7. {**  using yukky "Raw" API functions.                              **}
  8. {**                                                                **}
  9. {**  Version History :                                             **}
  10. {**                                                                **}
  11. {**  A0.01     Initial version started                   27/10/96  **}
  12. {**                                                                **}
  13. {** Copyright ⌐1996 Warren F. Young                                **}
  14. {********************************************************************}
  15. interface
  16. uses
  17.   Windows, { Standard Units }
  18.   CommCtrl,
  19.   SysUtils,
  20.   Messages,
  21.  
  22.   Global,{ Application Specific Units }
  23.   Resource;
  24.  
  25.  
  26. {********************************************************************}
  27. {**  public function definitions                                   **}
  28.  
  29. function PropExtCallback(Wnd: HWnd; Msg: Integer; PPSP: PPropSheetPageA):Integer stdcall;
  30. function PropExtDlgProc(Dialog: HWnd; AMessage, WParam: UINT; LParam: Longint):longBool; stdcall;
  31.  
  32. {********************************************************************}
  33. implementation
  34.  
  35. type
  36.   PPropInfo = ^TPropInfo;
  37.   TPropInfo = record
  38.                 PropPage  : TPropSheetPage;
  39.               end;
  40.  
  41.  
  42. {********************************************************************}
  43. {**  Function : WindowFromID                                       **}
  44. {**                                                                **}
  45. {**  Description : This function returns the window handle of a    **}
  46. {**  control with the given ID. Requires parent window handle.     **}
  47. {********************************************************************}
  48. function WindowFromID( Parent : HWnd; ID : integer):hWnd;
  49. var
  50.   hWndControl : hWnd;
  51. begin
  52.   hWndControl:=GetTopWindow(Parent); { get the top one }
  53.   repeat
  54.     if GetWindowLong(hWndcontrol,GWL_ID)=ID then break; { just quit out }
  55.     hWndControl:=GetNextWindow(hWndControl,GW_HWNDNEXT);
  56.   until hWndControl=0;{last window}
  57.   Result:=hWndControl;
  58. end;
  59.  
  60.  
  61. {********************************************************************}
  62. {**  Function : OnCreate                                           **}
  63. {**                                                                **}
  64. {**  Description : This function handles WM_InitDialog messages    **}
  65. {********************************************************************}
  66. function OnCreate(Dialog: HWnd; AMessage, WParam: UINT; LParam: Longint): longBool;
  67. var
  68.   Info          : PPropInfo;
  69.   MWWFile       : integer;
  70.   FileName      : string;
  71.   FileIDStr     : array[0..10] of char;
  72.   Title,Composer: array[0..255] of char;
  73.   S             : String;
  74.   Key1, Key2    : byte;
  75. begin
  76.   {** Create Info structure to store useful variables **}
  77.   GetMem(Info,Sizeof(TPropInfo)); { allocate memory }
  78.   Info^.PropPage:=PPropSheetPage(LParam)^; { copy page into }
  79.   SetWindowLong(Dialog,GWL_USERDATA,longint(Info)); { store it in window }
  80.   FillChar(FileIDStr, sizeof(FileIDStr), 0);
  81.   FillChar(Title, sizeof(Title), 0);
  82.   FillChar(Composer, sizeof(Composer), 0);
  83.  
  84.   {** Try reading in the file **}
  85. {  assignfile(MWWFile,PChar(Info^.PropPage.lParam));
  86.   reset(MWWFile,1); {}
  87.   MWWFile := FileOpen(PChar(Info^.PropPage.lParam), fmOpenRead);
  88.   try
  89.   try
  90.     FileRead(MWWFile,FileIDStr,sizeof(FileIDStr)); { read in file id string }
  91.     S := StrPas(@FileIDStr);
  92.     If copy(S, 1, 11) <> 'music works' then {not a real *.mww file}
  93.     begin
  94.       Title := 'unknown - file not valid';
  95.       Composer := 'unknown - file not valid';
  96.     end
  97.     else begin
  98.     FileSeek(MWWFile,21,0); { Offset to byte number 22 }
  99.     FileRead(MWWFile,Title,sizeof(Title)); {read in title}
  100.     FileRead(MWWFile,Composer,sizeof(Composer)); {read in composer}
  101.     FileSeek(MWWFile, $5FB, 0);
  102.     FileRead(MWWFile, Key1, 1);
  103.     FileSeek(MWWFile, $5FD, 0);
  104.     FileRead(MWWFile, Key2, 1);
  105.     end;
  106.   except
  107.     On EInOutError do { nothing };
  108.   end;
  109.   finally
  110.     FileClose(MWWFile);
  111.   end;  { try finally }
  112.  
  113.   Filename := {StrPas}(PChar(Info^.PropPage.lParam));
  114.   Filename := ExtractFileName(Filename);
  115. {  SendMessage(WindowFromID(Dialog,id_Filename),WM_SetText,0,UINT(Info^.PropPage.lParam));{}
  116.   SendMessage(WindowFromID(Dialog,id_Filename),WM_SetText,0,UINT(@FileName[1]));
  117.   SendMessage(WindowFromID(Dialog,id_SongTitle),WM_SetText,0,UINT(@Title));
  118.   SendMessage(WindowFromID(Dialog,id_Composer),WM_SetText,0,UINT(@Composer));
  119.     If key1 = 1 then
  120.     begin { music key is with sharps }
  121.        Case key2 of
  122.          1 : {key = G } S := 'G major';
  123.          2 : {key = D } S := 'D major';
  124.          3 : {key = A } S := 'A major';
  125.          4 : {key = E } S := 'E major';
  126.          5 : {key = G } S := 'B major';
  127.          6 : {key = G } S := 'F# major';
  128.          7 : {key = G } S := 'C# major';
  129.        else S := 'More than 7 or less than 1 sharps';
  130.        end;  { case }
  131.     end else
  132.     If key1 = 2 then
  133.     begin { music key is with flats }
  134.        Case key2 of
  135.          1 : {key = F } S := 'F major';
  136.          2 : {key = Bb} S := 'Bb major';
  137.          3 : {key = Eb} S := 'Eb major';
  138.          4 : {key = Ab} S := 'Ab major';
  139.          5 : {key = Db} S := 'Db major';
  140.          6 : {key = Gb} S := 'Gb major';
  141.          7 : {key = Cb} S := 'Cb major';
  142.        else S := 'More than 7 or less than 1 flats';
  143.        end;  { case }
  144.     end else
  145.     If key1 = 0 then { key = C }
  146.       S := 'C major'
  147.     else S := 'unknown';
  148.   SendMessage(WindowFromID(Dialog,id_MusicKey),WM_SetText,0,UINT(S));
  149.   Result:=FALSE;
  150. end;
  151.  
  152.  
  153. {********************************************************************}
  154. {**  Function : OnCommand                                          **}
  155. {**                                                                **}
  156. {**  Description : This function handles WM_Command messages       **}
  157. {********************************************************************}
  158. function OnCommand(Dialog: HWnd; AMessage, WParam: UINT; LParam: Longint): longBool;
  159. var
  160.   Info        : PPropInfo;
  161. begin
  162.   Info:=pointer(GetWindowLong(Dialog,GWL_USERDATA)); { get TPropInfo }
  163.  
  164.   case WParam of
  165.  
  166.   id_AboutBox      :
  167.     MessageBox( Dialog,'Properties of Music Works2 files'#13#10'Copyright (c) 1996 Warren F. Young'#13#10'Freeware',
  168.                 'About',mb_OK OR mb_IconInformation);
  169.   end;
  170.  
  171.   Result:=FALSE;
  172. end;
  173.  
  174.  
  175. {********************************************************************}
  176. {**  Function : TPropInfo.OnNotify                                 **}
  177. {**                                                                **}
  178. {**  Description : This function handles WM_Notify messages        **}
  179. {********************************************************************}
  180. function OnNotify(Dialog: HWnd; AMessage, WParam: UINT; LParam: Longint): longBool;
  181. begin
  182.   case PNMHdr(lParam)^.code of
  183.  
  184.   PSN_APPLY : SetWindowLong(Dialog,DWL_MSGRESULT,longint(TRUE));
  185.  
  186.   PSN_KILLACTIVE : begin
  187.                      SetWindowLong(Dialog,DWL_MSGRESULT,longint(FALSE));
  188.                      Result:=TRUE;
  189.                      exit;
  190.                    end;
  191.  
  192.   PSN_RESET: begin
  193.                SetWindowLong(Dialog,DWL_MSGRESULT,longint(FALSE));
  194.              end;
  195.  
  196.   end;{of lParam case}
  197.   Result:=FALSE;
  198. end;
  199.  
  200. {********************************************************************}
  201. {**  Function : PropExtDlgProc                                     **}
  202. {**                                                                **}
  203. {**  Description : This function is the dialog callback function   **}
  204. {**  for the property page and is responsible for all the UI funcs **}
  205. {********************************************************************}
  206. function PropExtDlgProc(Dialog: HWnd; AMessage, WParam: UINT; LParam: Longint): longBool; stdcall;
  207. begin
  208.   case AMessage of
  209.  
  210.   WM_InitDialog : Result:=OnCreate(Dialog,AMessage,WParam,LParam);
  211.  
  212.   WM_Command : Result:=OnCommand(Dialog,AMessage,WParam,LParam);
  213.  
  214.   WM_Notify : Result:=OnNotify(Dialog,AMessage,WParam,LParam);
  215.  
  216.   else
  217.     Result:=FALSE;
  218.   end; {of case}
  219. end;
  220.  
  221.  
  222. {********************************************************************}
  223. {**  Function : PropExtCallback                                    **}
  224. {**                                                                **}
  225. {**  Description : This function is the property page callback     **
  226. {**  which deals with the setup and removal of the page & stuff    **}
  227. {********************************************************************}
  228. function PropExtCallback(Wnd: HWnd; Msg: Integer; PPSP: PPropSheetPageA): Integer; stdcall;
  229. var
  230.   Info : PPropInfo;
  231. begin
  232.   case Msg of
  233.  
  234.   PSPCB_Create  : inc(RefThisDLL); {** make sure we don't get the rug pulled **}
  235.   PSPCB_Release : begin
  236.                     Info:=pointer(GetWindowLong(Wnd,GWL_USERDATA));
  237.                     FreeMem(Info,sizeof(TPropInfo));
  238.                     FreeMem(pointer(PPSP.lParam),MAX_PATH);
  239.                     dec(RefThisDLL); {** make sure we can release the DLL **}
  240.                   end;
  241.  
  242.   end;
  243.   Result:=1; { always allow creation }
  244. end;
  245.  
  246.  
  247. end.
  248. {********************************************************************}
  249.